//
// Created by yunnan xu on 2020/12/6.
//

#ifndef ANDROIDGRAPHICSDEMOS_MESHHELPER_H
#define ANDROIDGRAPHICSDEMOS_MESHHELPER_H

#include "Singleton.h"
#include "VertexAttrib.h"
#include <unordered_map>
#include <memory>

class MeshFileParser
{
public:

    virtual ~MeshFileParser() = default;
    virtual void FillMeshData(const unsigned char * model_data, int data_length, std::unordered_map<VertexAttribType, uint8_t*> & vertex_data, uint8_t * index_data) = 0;

};


class ObjFileParser : public MeshFileParser
{
public:

    virtual ~ObjFileParser() = default;
    virtual void FillMeshData(const unsigned char * model_data, int data_length, std::unordered_map<VertexAttribType, uint8_t*> & vertex_data, uint8_t * index_data);

private:

    void GetFaceIndex(const char * start, int str_len, std::vector<int> & result);

};


class MeshHelper : public Singleton<MeshHelper>
{
public:

    MeshHelper();
    void GetMeshData(const char * file_path, std::unordered_map<VertexAttribType, uint8_t*> & vertex_data, uint8_t * index_data);

private:

    std::shared_ptr<MeshFileParser> objFileParser;
};


#endif //ANDROIDGRAPHICSDEMOS_MESHHELPER_H
